// 计算时间差的一个小工具
var DateDiff = (function() {
	var defaultOpts = {
			textFormat : '${NUM}${PERIOD}前'
	}
	function getDiff(opts) {
		opts = opts || {}
		opts = $.extend({}, opts, defaultOpts)
		var curDate = opts['curDate']
		var textFormat = opts['textFormat']
		var systemDate = new Date()
		if ( !curDate ) reutrn 'Invalid Date: ' + curDate
		
		var millis = systemDate.getTime() - curDate.getTime()
		var seconds = millis / 1000,
			minutes = seconds / 60,
			hour = minutes / 60,
			day = hour / 24;
		
		var num = seconds, period = '秒';
		if ( day > 1 ) {
			num = day
			period = '天'
		} else if ( hour > 1 ) {
			num = hour
			period = '小时'
		} else if ( minutes > 1 ) {
			num = minutes
			period = '分'
		}  
		num = Math.ceil(num)
		return textFormat.replace(/\$\{NUM\}/g, num).replace(/\$\{PERIOD\}/g, period)
	}
	
	return {
		getDiff: getDiff
	}
	
})()